package com.example.fragmentbaseproactice.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.fragmentbaseproactice.R;
import com.example.fragmentbaseproactice.entity.News;

import java.util.List;

public class NewsAdapter extends ArrayAdapter {

    private int resourcesId;
    public NewsAdapter(@NonNull Context context, int resource, List<News> objects) {
        super(context, resource,objects);
        resourcesId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        News news = (News) getItem(position);

        View view;
        if(convertView == null){
            //理解
            view = LayoutInflater.from(getContext()).inflate(resourcesId,null);
        }else {
            view = convertView;
        }
        TextView textView = (TextView) view.findViewById(R.id.title);
        textView.setText(news.getTitle());
        return view;
    }
}
